<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\StoreImage;
use App\Http\Requests\UpdateConfig;
use App\Models\Config;
use App\Models\Image;
use App\Models\Store;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ConfigController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function __construct()
    {


    }



    public function config($id)
    {
        view()->share([
            '_config' => 'am-in',
            '_info' => 'am-active',
        ]);
        $config = Store::find($id);

        return view('admin.system.config', compact('config'));
    }


    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function save(UpdateConfig $request)

    {
        $config = Config::find($request->id);
        $config->update($request->all());
        return redirect('admin/store')->with('success', '修改成功');
    }


    public function index()
    {

        view()->share([
            '_config' => 'am-in',
            '_image' => 'am-active',
        ]);
        $images = Image::orderBy('sort')->paginate(10);
        return view('admin.system.index', compact('images'));


    }

    public function create()
    {


        return view('admin.system.create');


    }

    public function store(StoreImage $request)
    {
        Image::create($request->all());
        return redirect('/admin/system/image')->with('success', '新增成功');

    }

    public function destroy($id)
    {
        Image::destroy($id);
        return back()->with('success', '删除成功');

    }

    public function sort(Request $request){
        $image = Image::find($request->id);
        $image->sort = $request->sort;
        $image->save();
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */

}
